#include<iostream>
#include<unistd.h>
#include<fcntl.h>

void setnoblock(int fd)
{
  int f1=fcntl(fd,F_GETFD);
  if(f1<0)
  {
    std::cerr<<"fcntl"<<std::endl;
    return ;
  }
  fcntl(fd,F_SETFD,f1|O_NONBLOCK);

}
int main()
{
  setnoblock(0);
  while (1) {
  char buf[1024] = {0};
  ssize_t read_size = read(0, buf, sizeof(buf) - 1);
    if (read_size < 0) {
  std::cout<<"read"<<std::endl;
   sleep(1);
   continue;
    }
    std::cout<<buf<<std::endl;
 }
  return 0;
}
